package com.eigland.eigaland_lib.model

import android.content.Context
import com.eigland.eigaland_lib.R
import com.eigland.eigaland_lib.extensions.isExpired
import com.google.gson.annotations.SerializedName
import org.joda.time.Instant
import java.util.ArrayList

data class Cinema(
    val name: String = "",
    val uuid: String = "",
    val description: String = "",
    val address: String = "",
    val phoneNumber: String = ""
) : Model

data class Role(
    val name: String = "",
    val privileges: List<String> = emptyList(),
    val uuid: String = "",
    val accessibilities: List<Accessibility> = emptyList(),
    val posAccess: Boolean
) : Model


data class ShowCount(
    val available: Int = 0,
    val total: Int = 0
) : Model

data class Section(
    var w: Int = 20,
    var h: Int = 20,
    val x: Float = 0f, // x coordinate
    var y: Float = 0f, // y coordinate
    val r: Float = 0f, // rotation angle
    val seats: List<Seat> = listOf(),
    val labels: List<Label> = listOf(),
    val bgColor: String? = ""
) : Model


data class Label(
    val x: Int = 0,
    var y: Int = 0,
    val w: Int? = 0,
    val h: Int? = 0,
    val color: String? = "#FFFFFF",
    val text: String = "",
    val fontSize: Float? = 20.0f,
    val bgColor: String? = "",
    val bgImg: String? = ""
) : Model

data class StandingArea(
    val capacity: Int = 0,
    val sold: Int = 0
) : Model

data class TicketRecordItem(
    val orderId:String,
    val seatId:String,
    val ticketName:String,
    val vipPrice :Int,
    val couponTypes : ArrayList<CouponType>,
    val ticketId :String

):Model


data class TransactionWithPaymentType(
    val paymentType: PaymentType?,
    val transaction: Transaction
) : Model


data class PaymentType(
    val name: String = "",
    val uuid: String = "",
    val pid: String="CASH"
) : Model


data class CouponType(
    val addCommercial:Boolean = false,
    override val name: String = "",
    val description: String = "",
    val finalPrice: String = "",
    val boxOffice: Boolean = false,
    val providingDiscount: Boolean = false,
    val discount: Float = 0.0f,
    val baseType: String = "",
    val imageUrl: String = "",
    val sort: Int = 0,
    override val fontColor: String = "",
    override val bgColor: String = "",
    val scheduleType: String = "",
    val scheduleValue: String = "",
    val noScheduleWeek: List<String> = emptyList(),
    val noScheduleMonth: List<String> = emptyList(),
    val status: String = "",
    val displayVipSeat: Boolean = false,
    val displaySpecialSeat: Boolean = true,
    val displayPos: Boolean = true,
    val displayOnline: Boolean = true,
    val couponTypeCategoryRef: String = "",
    override val uuid: String,
    override val unitPrice: Float,
    override val imgUrl: String,
    override val taxRate: Float
) : ITicketConcession{

    companion object{
        val QUOTA:String="QUOTA"
        val DISCOUNT:String="DISCOUNT"
    }
}

interface ITicketConcession {
    val name: String
    val uuid: String
    val unitPrice: Float
    val bgColor: String
    val fontColor: String
    val imgUrl: String
    val taxRate: Float
}


data class Transaction(
    val totalPrice: Float = 0f,
    val totalTax: Float = 0f,
    val totalRounding: Float = 0f,
    val total: Float = 0f,
    val paidAmount: Long = 0L,
    val status: Status = Status.PROCESSING,
    val uuid: String = "",
    val createAt: String = "",
    val updateAt: String = "",
    val searchId: String = "",
    val couponTotal:Float= 0f,
    val paymentRef: String = "",
    val receiptIssued: Boolean = false,
    val invoiceIssued: Boolean = false,
    val vipSeatTotal: Float = 0f
) : Model {
    enum class Status {
        PROCESSING, CHARGED, REFUNDED, VOID, PARTIAL_REFUNDED,CONFIRMING;

        override fun toString(): String {
            return when (this) {
                PROCESSING -> "Processing"
                CHARGED -> "Charged"
                REFUNDED -> "Refunded"
                VOID -> "Void"
                PARTIAL_REFUNDED -> "Partial Refunded"
                CONFIRMING -> "confirming"
            }
        }

    }
}

data class SeatPlan(
    var w: Int = 0,
    val h: Int = 0,
    val bgColor: String = "",
    val sections: List<Section> = listOf(),
    var con: CongestionLevel = CongestionLevel(),
    val defSeatW: Int = 0,
    val defSeatH: Int = 0,
    val defSeatColor: String = "",
    val defSeatBgColor: String = "",
    val defSeatBgImg: String = "",
    val defSeatColorReserved: String = "",
    val defSeatBgColorReserved: String = "",
    val defSeatColorSold: String = "",
    val defSeatBgColorSold: String = "",
    val defSeatColorSelected: String = "",
    val defSeatBgColorSelected: String = "",
    val defSeatBgImgSelected: String = "",
    val defSeatFontSize: Float = 0f,
    val defLabelW: Int = 50,
    val defLabelH: Int = 50,
    val defLabelColor: String = "",
    val defLabelFontSize: Float = 0f,
    val defLabelBgColor: String? = "",
    val defLabelBgImg: String? = "",
    val pairSeats: String? = ""


//  val params: Params = Params()
) : Model

data class Show(
    val startTime : String = "",
    val endTime: String = "",
    val uuid: String = "",
    val freeSeat: Boolean = false):Model

data class MovieVersion(
    val name: String = "",
    val uuid: String = "",
    val imageUrl: String = "",
    val duration: Int = -1,
    val additionalCharge: Float = -1f
) : Model

data class VersionTag(
    val message: String = "",
    val messageBoxType: MessageBoxType = MessageBoxType.OKAY,
    val name: String = "",
    val yesButtonText: String = "",
    val noButtonText: String = "",
    val okButtonText: String = "",
    val prompt: Prompt = Prompt.NA,
    val uuid: String = ""
) : Model {
    enum class MessageBoxType { YES_NO_EXIT, OKAY, YES_NO_PROCEED }
    enum class Prompt { ENTRY, TICKETING, NA }
}

data class OperationDay(
    val date: String = "",
    val uuid: String = ""
) : Model

data class Seat(
    val x: Int = 0,
    var y: Int = 0,
    var w: Int? = 50,
    var h: Int? = 50,
    val sid: String = "",
    val text: String = "",
    val textSize: Float? = 20f,
    @SerializedName("s")
    var availability: String = "",
    val color: String? = "#000000",
    val bgColor: String? = "#54f26f",
    val colorSelected: String? = "#FFE000",
    val bgColorSelected: String? = "#000000",
    val colorSold: String? = "#FFFFFF",
    val bgColorSold: String? = "#F82A2A",
    val colorReserved: String? = "#000000",
    val bgColorReserved: String? = "#BBBBBB",
    val bgImg: String? = "",
    val bgImgSelected: String? = "",
    var isSelected: Boolean = false,
    var freeSeat:Boolean=false
) : Model {
    enum class Availability(val s: String) {
        Available("O"), Sold("S"), NotAvailable("N"), Reserved("R"), VIP("V"), Special("P"), OC("OC");
    }


    class Status {
        companion object {
            val OPEN = "OPEN"
            val CLOSE = "CLOSE"
        }
    }

    val isAvailable: Boolean = when (availability) {
        Availability.VIP.s,
        Availability.Available.s,
        Availability.Special.s,
        Availability.OC.s,
        Availability.Sold.s
        -> true
        else -> false
    }

}

data class CongestionLevel(
    val colorCode: String = "",
    val message: String = "",
    val purchasable: Boolean = true,
    val createAt: String = "",
    val lv1ColorCode: String = "",
    val lv1Message: String = "",
    val lv1Occupancy: String = "",
    val lv1Purchasable: String = "",
    val lv2ColorCode: String = "",
    val lv2Message: String = "",
    val lv2Occupancy: String = "",
    val lv2Purchasable: String = "",
    val lv3ColorCode: String = "",
    val lv3Message: String = "",
    val lv3Occupancy: String = "",
    val lv3Purchasable: String = "",
    val lv4ColorCode: String = "",
    val lv4Message: String = "",
    val lv4Occupancy: String = "",
    val lv4Purchasable: String = "",
    val lv5Additional: String = "",
    val lv5ColorCode: String = "",
    val lv5CouponID: String = "",
    val lv5Discounted: String = "",
    val lv6Additional: String = "",
    val lv6ColorCode: String = "", //LV6 is special color code
    val lv6Discounted: String = "",
    val lv7Additional: String = "",
    val lv7ColorCode: String = "", //  LV7 is vip color code
    val lv7CouponID: String = "",
    var lv7Discounted: String = "",
    val lv7VipSeatName: String = "",
    var seat: ArrayList<Seat>? = null


) : Model

data class Shift(
    val uuid: String = "",
    val openAmount: Double = 0.0,
    val bill1000: Int = 0,
    val bill10000: Int = 0,
    val bill2000: Int = 0,
    val bill5000: Int = 0,
    val closeAmount: Double = 0.0,
    val coin1: Int = 0,
    val coin10: Int = 0,
    val coin100: Int = 0,
    val coin5: Int = 0,
    val coin50: Int = 0,
    val coin500: Int = 0,
    val difference: Double = 0.0
) : Model

data class MyUserAccount(
    val loginInfo: LoginInfo?,
    val accountInfo: AccountInfo?
) : Model {
    fun canReprint(): Boolean = accountInfo?.roles?.any { it.accessibilities.contains(Accessibility.POS) }
        ?: false
}

data class LoginInfo(
    val username: String,
    val password: String = ""
) : Model

data class OAuthToken(
    val token: String,

    val refreshToken: String,
    @SerializedName("tokenExpiration") val expireTime: String,
    @SerializedName("refreshTokenExpiration") val refreshTokenTime: String
) : Model {
    fun isExpired(): Boolean = expireTime.isEmpty()
}

data class AccountInfo(
    val oAuthToken: OAuthToken,
    val device: Device,
    val cinema: Cinema,
    val user: User,
    val roles: List<Role>,
    val shift: Shift?
) : Model

data class User(
    val name: String = "",
    val uuid: String = "",
    val imgUrl: String? = ""
) : Model

data class House(
    val name: String = "",
    val uuid: String = ""
) : Model

enum class Accessibility(val right: String) {
    @SerializedName("CANCEL_REFUND_TRANSACTION")
    POS("CANCEL_REFUND_TRANSACTION"),
    @SerializedName("EDIT_MOVIE")
    CMS_DATA_1("EDIT_MOVIE"),
    @SerializedName("EDIT_SHOWTIME")
    CMS_DATA_2("EDIT_SHOWTIME"),
    @SerializedName("EDIT_TICKET_TICKETTYPE")
    CMS_DATA_3("EDIT_TICKET_TICKETTYPE"),
    @SerializedName("EDIT_STORE")
    CMS_DATA_4("EDIT_STORE"),
    @SerializedName("BLOCK_TO_SELL")
    CMS_SEAT_1("BLOCK_TO_SELL"),
    @SerializedName("SET_SPARE_SEAT")
    CMS_SEAT_2("SET_SPARE_SEAT"),
    @SerializedName("BROWSE_EXPORT_REPORT")
    CMS_REPORT("BROWSE_EXPORT_REPORT"),
    @SerializedName("ISSUE_INVOICE")
    CMS_INVOICE("ISSUE_INVOICE"),
    @SerializedName("EDIT_ACCOUNT_ROLE")
    CMS_SETTING_1("EDIT_ACCOUNT_ROLE"),
    @SerializedName("EDIT_PAYMENT")
    CMS_SETTING_2("EDIT_PAYMENT"),
    @SerializedName("STOP_RESTART_OPERATION")
    CMS_SETTING_3("STOP_RESTART_OPERATION")
}

data class MovieInfo(
    val casts: List<String> = listOf(),
    val category: String = "",
    val copyRight: String = "",
    val countries: List<String> = listOf(),
    val directors: List<String> = listOf(),
    val distributor: String = "",
    val genres: List<String> = listOf(),
    val id: Int = -1,
    val officialPageUrl: String = "",
    val openDateCustomFormat: String = "",
    val synopsis: String = "",
    val trailerUrl: String = ""
) : Model


data class Coupon(var id:String,var couponNum:String):Model

data class Movie(
    val name: String = "",
    val posterUrl: String = "",
    val durationMin: Int = 0,
    val openDate: String = "",
    val uuid: String = "",
    val category: String = ""
) : Model

public open class Error():Model{
    val timestamp:String = ""
    val status:Int = 0
    val error:String = ""
    val exception:String = ""
    val message:String = ""
}